<?php
    define('WP_USE_THEMES', false); 
    
    require('./wp-blog-header.php');
    require('./DBHandler.php');

    $dbHandler = new DBHandler;

    $courseid = '';

    if ($_GET)
    {
        $courseid = $_GET['courseid'];

        $course = $dbHandler->GetCourse($courseid);
    }

?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <h2>Manage assignments for <?php echo $course->Name ?></h2>
        <a href="managecourses.php">Back to Manage Courses</a>
        <br/><br/>
        <a href="manageassignment.php?courseid=<?php echo $courseid?>&op=create">Create new assignment</a><br/>
        <table border="1">
            <tr>
                <th>Title</th>
                <th>Author</th>
                <th>Edit</th>
                <th>Delete</th>
                <th>Manage Submissions</th>
            </tr>
            <?php
                if ($course)
                {
                    $rows = $dbHandler->GetAllAssignments($courseid);

                    foreach($rows as $row)
                    {
                        echo "<tr>";
                        echo "<td>" . $row->Title . "</td>";
                        echo "<td>" . $row->AuthorName . "</td>";
                        echo "<td><a href='ManageAssignment.php?courseid=" . $courseid . "&assignmentid=" . $row->AssignmentId . "&op=edit'>Edit</a></td>";
                        echo "<td><a href='ManageAssignment.php?courseid=" . $courseid . "&assignmentid=" . $row->AssignmentId . "&op=delete'>Delete</a></td>";
                        echo "<td><a href='ManageSubmissions.php?courseid=" . $courseid . "&assignmentid=" . $row->AssignmentId . "'>Manage Submissions</a></td>";
                        echo "</tr>";
                    }
                }
            ?>
        </table>
    </body>
</html>
